<?  include('../includes/loader.inc.php'); 

	$config = array (
		'title' 	=> 'Home',
		'module' 	=> 'home',
		'class'		=> 'Home',
		'key'		=> 'id_proyecto',
	);

	// Instancio la clase
	$obj = new $config['class']();

	if ($_GET['eliminar'])
		$obj->imagen_eliminar($_GET['eliminar']);

//if ($_FILES)
//	die('<pre>FILES: '.print_r($_FILES, true).'</pre>'.'<pre>POST: '.print_r($_POST, true).'</pre>');

	if ($_FILES)
		foreach ($_FILES['data']['tmp_name']['Home']['imagenes'] as $k => $v)
			if (!empty($v))
				$obj->imagen_agregar($v, $_FILES['data']['name']['Home']['imagenes'][$k]);

	if ($_POST['data']['orden']) {

		$obj->imagenes_ordenar($_POST['data']);
			
		// Redirecciono
		header("Location: ".(($url = $Session->get($config['module'].'_listado'))? $url : '/admin/'.$config['module'].'/'));
		exit;
	}

	// Obtengo las imagenes
	$imagenes = $obj->imagenes();

//echo '<pre>'.print_r($row, true).'</pre>';

?>
<!DOCTYPE html>

<html>

<head>
	
	<title><?=$config['title']?></title>

	<?	include('modules/head.inc.php'); ?>
	
</head>

<body class="<?=$admin['config']['theme']?>">

	<!--<div class="login-back"></div>

	<div class="titlebar"></div>
	
	<div class="window">
	
		<div class="content">-->

			<?  include('modules/header.inc.php'); ?>

			<div class="space clear"></div>

			<div class="container" data-object="">
			
				<h2><?=$config['title']?></h2>
				
				<div class="space clear"></div>
			
				<!-- Content -->

				<form method="post" enctype="multipart/form-data" action="<?=$PHP_SELF?>" class="edit">
					<!-- hidden -->
					<input type="hidden" name="data[<?=$config['class']?>][primary_key]" value="<?=$config['key']?>">
					<input type="hidden" name="data[<?=$config['class']?>][<?=$config['key']?>]" value="<?=$_GET['id']?>">
					
					<div class="legend"><h3>Imagenes de la home</h3></div>
						

						<ul class="list image-list">

							<?	if ($imagenes):
									foreach ($imagenes as $k => $v): 
							?>
							<li>
								<p><img style="height: 50px;" src="<?=$v['img']?>"></p>
								<p>Orden<input type="text" style="width: 40px;" name="data[orden][<?=$v['id_home_image']?>]" value="<?=$v['orden']?>"></p>
								<p>T&iacute;tulo: <input type="text" name="data[titulo][<?=$v['id_home_image']?>]" value="<?=$v['titulo']?>"></p>
								<p>Texto: <input type="text" name="data[texto][<?=$v['id_home_image']?>]" value="<?=$v['texto']?>"></p>
								<p><a onClick="return confirm('Estas seguro que queres borrar esta imagen?');" href="/admin/<?=$config['module']?>/?eliminar=<?=$v['id_home_image']?>"><span class="icon ui-icon-trash"></span>Borrar</a></p>
							</li>
							<?		endforeach;
								endif;
							?>
							<li>
								<p>Seleccionar una imagen</p>
								<p>
									<input type="file" name="data[<?=$config['class']?>][imagenes][]" value=""/>
								</p>
							</li>
						</ul>

						<ul class="list">
							<li>
								<p></p>
								<p style="text-align: right;"><a href="#" id="add-image">Agregar otra imagen</a></p>
							</li>
						</ul>
					
					<?#	endforeach; ?>
						
					<div class="submits">
					
						<button type="submit" name="action" value="Guardar" class="capitalize button">Guardar</button>
						
					</div>

				</form>


				<!-- /Content -->

				
			</div>

			<?	include('modules/footer.inc.php'); ?>
		
		<!--</div>
		
	</div>-->
			
	<script src="/admin/js/universal.js"></script>

</body>	
	
</html>

